﻿// ----------------------------------------------------------------
// Description : 实体类,该文件由MyGeneration生成
// Author      : 
// Create date : 2009-12-05
// ----------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace ITOMMS.Entity
{
	/// <summary>
	///	tbTroubleForm Entity
	///	tbTroubleForm Entity故障信息表
	/// </summary>
	[Serializable]
	public class tbTroubleFormEntity : BaseEntity<tbTroubleFormEntity,int>
	{
		
		#region 私有成员			
		
		private int _ID; 
		private string _TroubleNo; 
		private int? _ModifyBy; 
		private int? _ServiceID; 
		private int? _TroubleAsset; 
		private int? _TaskSource; 
		private string _ShortServiceName; 
		private int? _TroubleClassID; 
		private string _TroubleDescription; 
		private int? _AppendixID; 
		private int? _RequestUserID; 
		private DateTime? _RequestTime; 
		private DateTime? _ExpectTime; 
		private int? _State; 
		private string _Incidence; 
		private string _UrgencyDegree; 
		private int? _NextDepartment; 
		private int? _NextPerson; 
		private string _TransactComments; 
		private string _Feedback; 
		private DateTime? _CreateDate; 
		private int? _CreateBy; 
		private DateTime? _ModifyDate; 
		private int _OwnerCompnayID; 
		private int _SEQNO;
		#endregion


		
		#region 默认( 空 ) 构造函数
		/// <summary>
		/// 默认构造函数
		/// </summary>
		public tbTroubleFormEntity()
		{
			_ID = 0; 
			_TroubleNo = String.Empty; 
			_ModifyBy =  null; 
			_ServiceID =  null; 
			_TroubleAsset =  null; 
			_TaskSource =  null; 
			_ShortServiceName = String.Empty; 
			_TroubleClassID =  null; 
			_TroubleDescription = String.Empty; 
			_AppendixID =  null; 
			_RequestUserID =  null; 
			_RequestTime =  null; 
			_ExpectTime =  null; 
			_State =  null; 
			_Incidence = String.Empty; 
			_UrgencyDegree = String.Empty; 
			_NextDepartment =  null; 
			_NextPerson =  null; 
			_TransactComments = String.Empty; 
			_Feedback = String.Empty; 
			_CreateDate =  null; 
			_CreateBy =  null; 
			_ModifyDate =  null; 
			_OwnerCompnayID = 0; 
			_SEQNO = 0;
		}
		#endregion
		
		#region 属性值校验
		
		/// <summary>
		/// 属性值校验
		/// </summary>
		public bool CheckValues()
		{
			bool bResult = true;
			string strError = "";
		
			if ( _ID ==  0)
			{
				bResult = false;
				strError += "\r\n 非空值不能为: "+_ID;
			}
			
			if ( _OwnerCompnayID ==  0)
			{
				bResult = false;
				strError += "\r\n 非空值不能为: "+_OwnerCompnayID;
			}
			
			if( !bResult )
					throw new ArgumentOutOfRangeException(strError);
			return bResult;
			
		}
		
		#endregion
		
		
		
	
		#region Required Fields Only Constructor
		
		/// <summary>
		/// required (not null) fields only constructor
		/// </summary>
		public tbTroubleFormEntity(
		int para_ID, int para_OwnerCompnayID		)
		: this()
		{
					_ID = para_ID;
			_TroubleNo = String.Empty;
			_ModifyBy = null;
			_ServiceID = null;
			_TroubleAsset = null;
			_TaskSource = null;
			_ShortServiceName = String.Empty;
			_TroubleClassID = null;
			_TroubleDescription = String.Empty;
			_AppendixID = null;
			_RequestUserID = null;
			_RequestTime = null;
			_ExpectTime = null;
			_State = null;
			_Incidence = String.Empty;
			_UrgencyDegree = String.Empty;
			_NextDepartment = null;
			_NextPerson = null;
			_TransactComments = String.Empty;
			_Feedback = String.Empty;
			_CreateDate = null;
			_CreateBy = null;
			_ModifyDate = null;
			_OwnerCompnayID = para_OwnerCompnayID;
		}
		#endregion 

		
		#region 公有属性
			
			/// <summary>
			/// 行号，顺序号。系统默认的属性,对这个属性不要作操作.属性值在架构中已经处理
			/// </summary>
			public virtual int SEQNO
			{
				get { return _SEQNO; }
				set { _SEQNO = value; }
			}
		
			
		/// <summary>
		/// IDID
		/// </summary>		
		public virtual int ID
		{
			get { return _ID; }
			set { _ID = value; }
		}
			
		/// <summary>
		/// TroubleNo编号
		/// </summary>		
		public virtual string TroubleNo
		{
			get { return _TroubleNo; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 30)
						throw new ArgumentOutOfRangeException("Invalid value for TroubleNo", value, value.ToString());
				
				_TroubleNo = value;
			}
		}
			
		/// <summary>
		/// ModifyBy修改人
		/// </summary>		
		public virtual int? ModifyBy
		{
			get { return _ModifyBy; }
			set { _ModifyBy = value; }
		}
			
		/// <summary>
		/// ServiceID服务类别
		/// </summary>		
		public virtual int? ServiceID
		{
			get { return _ServiceID; }
			set { _ServiceID = value; }
		}
			
		/// <summary>
		/// TroubleAsset故障来源(故障设备)
		/// </summary>		
		public virtual int? TroubleAsset
		{
			get { return _TroubleAsset; }
			set { _TroubleAsset = value; }
		}
			
		/// <summary>
		/// TaskSource事件来源
		/// </summary>		
		public virtual int? TaskSource
		{
			get { return _TaskSource; }
			set { _TaskSource = value; }
		}
			
		/// <summary>
		/// ShortServiceName服务名称
		/// </summary>		
		public virtual string ShortServiceName
		{
			get { return _ShortServiceName; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 30)
						throw new ArgumentOutOfRangeException("Invalid value for ShortServiceName", value, value.ToString());
				
				_ShortServiceName = value;
			}
		}
			
		/// <summary>
		/// TroubleClassID故障类别
		/// </summary>		
		public virtual int? TroubleClassID
		{
			get { return _TroubleClassID; }
			set { _TroubleClassID = value; }
		}
			
		/// <summary>
		/// TroubleDescription故障描述
		/// </summary>		
		public virtual string TroubleDescription
		{
			get { return _TroubleDescription; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 2147483647)
						throw new ArgumentOutOfRangeException("Invalid value for TroubleDescription", value, value.ToString());
				
				_TroubleDescription = value;
			}
		}
			
		/// <summary>
		/// AppendixID附件ID
		/// </summary>		
		public virtual int? AppendixID
		{
			get { return _AppendixID; }
			set { _AppendixID = value; }
		}
			
		/// <summary>
		/// RequestUserID申报人ID(请求人ID)
		/// </summary>		
		public virtual int? RequestUserID
		{
			get { return _RequestUserID; }
			set { _RequestUserID = value; }
		}
			
		/// <summary>
		/// RequestTime请求时间
		/// </summary>		
		public virtual DateTime? RequestTime
		{
			get { return _RequestTime; }
			set { _RequestTime = value; }
		}
			
		/// <summary>
		/// ExpectTime期望时间
		/// </summary>		
		public virtual DateTime? ExpectTime
		{
			get { return _ExpectTime; }
			set { _ExpectTime = value; }
		}
			
		/// <summary>
		/// State故障处理状态
		/// </summary>		
		public virtual int? State
		{
			get { return _State; }
			set { _State = value; }
		}
			
		/// <summary>
		/// Incidence影响范围
		/// </summary>		
		public virtual string Incidence
		{
			get { return _Incidence; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 30)
						throw new ArgumentOutOfRangeException("Invalid value for Incidence", value, value.ToString());
				
				_Incidence = value;
			}
		}
			
		/// <summary>
		/// UrgencyDegree紧急程度
		/// </summary>		
		public virtual string UrgencyDegree
		{
			get { return _UrgencyDegree; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 5)
						throw new ArgumentOutOfRangeException("Invalid value for UrgencyDegree", value, value.ToString());
				
				_UrgencyDegree = value;
			}
		}
			
		/// <summary>
		/// NextDepartment下一步处理部门
		/// </summary>		
		public virtual int? NextDepartment
		{
			get { return _NextDepartment; }
			set { _NextDepartment = value; }
		}
			
		/// <summary>
		/// NextPerson下一步处理人
		/// </summary>		
		public virtual int? NextPerson
		{
			get { return _NextPerson; }
			set { _NextPerson = value; }
		}
			
		/// <summary>
		/// TransactComments处理意见
		/// </summary>		
		public virtual string TransactComments
		{
			get { return _TransactComments; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 1500)
						throw new ArgumentOutOfRangeException("Invalid value for TransactComments", value, value.ToString());
				
				_TransactComments = value;
			}
		}
			
		/// <summary>
		/// Feedback反馈意见
		/// </summary>		
		public virtual string Feedback
		{
			get { return _Feedback; }
			set	
			{
				
				if ( value != null)
					if( value.Length > 1500)
						throw new ArgumentOutOfRangeException("Invalid value for Feedback", value, value.ToString());
				
				_Feedback = value;
			}
		}
			
		/// <summary>
		/// CreateDate创建时间
		/// </summary>		
		public virtual DateTime? CreateDate
		{
			get { return _CreateDate; }
			set { _CreateDate = value; }
		}
			
		/// <summary>
		/// CreateBy创建人
		/// </summary>		
		public virtual int? CreateBy
		{
			get { return _CreateBy; }
			set { _CreateBy = value; }
		}
			
		/// <summary>
		/// ModifyDate修改时间
		/// </summary>		
		public virtual DateTime? ModifyDate
		{
			get { return _ModifyDate; }
			set { _ModifyDate = value; }
		}
			
		/// <summary>
		/// OwnerCompnayID所属公司
		/// </summary>		
		public virtual int OwnerCompnayID
		{
			get { return _OwnerCompnayID; }
			set { _OwnerCompnayID = value; }
		}
			


		#endregion 	
		
		
        #region DAO操作
		
		
		/// <summary>
        /// 获取所有实体的列表
        /// </summary>
        /// <returns></returns>
        public override List<tbTroubleFormEntity> GetAll()
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("select [ID],[TroubleNo],[ModifyBy],[ServiceID],[TroubleAsset],[TaskSource],[ShortServiceName],[TroubleClassID],[TroubleDescription],[AppendixID],[RequestUserID],[RequestTime],[ExpectTime],[State],[Incidence],[UrgencyDegree],[NextDepartment],[NextPerson],[TransactComments],[Feedback],[CreateDate],[CreateBy],[ModifyDate],[OwnerCompnayID] from [tb_TroubleForm] ");
	
            List<tbTroubleFormEntity> list = new List<tbTroubleFormEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
				int seq = 0;
                while (dataReader.Read())
                {	seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		/// <summary>
        /// 获取所有实体的列表总行数
        /// </summary>
        /// <returns></returns>
        public override int GetTotalRecords()
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("  select count([ID])  from [tb_TroubleForm] ");
	
            Database db = GetDatabase();
            return (int)db.ExecuteScalar(CommandType.Text, strSql.ToString());
        }
		
		/// <summary>
        /// 获取所有实体的列表总行数
        /// </summary>
        /// <returns></returns>
        public override int GetTotalRecords(string sqlCondition)
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("  select count([ID])  from [tb_TroubleForm]  ");
	
			 if (sqlCondition.Trim() != "")
            {
                strSql.Append(" where " + sqlCondition);
            }
            Database db = GetDatabase();
            return (int)db.ExecuteScalar(CommandType.Text, strSql.ToString());
        }	
		
		
		/// <summary>
        /// 按条件查询,得到一页的对应的结果列表
        /// </summary>
        /// <param name="strWhere">条件</param>
		/// <param name="PageSize">每页大小</param>
		/// <param name="CurrentPageIndex">当前页码</param>
        /// <returns></returns>
		 public override List<tbTroubleFormEntity> GetAllByQuery(string strWhere, int PageSize, int CurrentPageIndex)
        {
            StringBuilder strSql = new StringBuilder();
            if (strWhere.Contains("order".ToLower()))
            {
                throw new Exception("分页查询的sql条件中不能包括排序子句，请调用重载方法实现有条件的排序筛选");
            }
		 
			strSql.Append("select top ").Append(PageSize).Append("  [ID],[TroubleNo],[ModifyBy],[ServiceID],[TroubleAsset],[TaskSource],[ShortServiceName],[TroubleClassID],[TroubleDescription],[AppendixID],[RequestUserID],[RequestTime],[ExpectTime],[State],[Incidence],[UrgencyDegree],[NextDepartment],[NextPerson],[TransactComments],[Feedback],[CreateDate],[CreateBy],[ModifyDate],[OwnerCompnayID] from [tb_TroubleForm] where ");

			 if (strWhere.Trim() != "")
            {
                strSql.Append("  " + strWhere + " and ");
            }
			  strSql.Append(" ID not in ( ");
			 strSql.Append(" select top ").Append(PageSize*(CurrentPageIndex-1)).Append("  [ID] from [tb_TroubleForm] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere );
            }
			strSql.Append(" ) " );

            List<tbTroubleFormEntity> list = new List<tbTroubleFormEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
			   int seq = PageSize * (CurrentPageIndex - 1);
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }
		
		
			/// <summary>
        /// 按条件查询,得到一页的对应的结果列表
        /// </summary>
        /// <param name="strWhere">条件</param>
		/// <param name="PageSize">每页大小</param>
		/// <param name="CurrentPageIndex">当前页码</param>
		/// <param name="strSort">ex:order by id desc</param>
        /// <returns></returns>
		 public override List<tbTroubleFormEntity> GetAllByQuery(string strWhere,string strSort, int PageSize, int CurrentPageIndex)
        {
            StringBuilder strSql = new StringBuilder();
            if (strWhere.Contains("order".ToLower()))
            {
                throw new Exception("分页查询的sql条件中不能包括排序子句，请调用重载方法实现有条件的排序筛选");
            }
		 
			strSql.Append("select top ").Append(PageSize).Append("  [ID],[TroubleNo],[ModifyBy],[ServiceID],[TroubleAsset],[TaskSource],[ShortServiceName],[TroubleClassID],[TroubleDescription],[AppendixID],[RequestUserID],[RequestTime],[ExpectTime],[State],[Incidence],[UrgencyDegree],[NextDepartment],[NextPerson],[TransactComments],[Feedback],[CreateDate],[CreateBy],[ModifyDate],[OwnerCompnayID] from [tb_TroubleForm] where ");

			 if (strWhere.Trim() != "")
            {
                strSql.Append("  " + strWhere + " and ");
            }
			  strSql.Append(" ID not in ( ");
			 strSql.Append(" select top ").Append(PageSize*(CurrentPageIndex-1)).Append("  [ID] from [tb_TroubleForm] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere+" " ).Append(strSort);
            }
			strSql.Append(" ) " ).Append(strSort);

            List<tbTroubleFormEntity> list = new List<tbTroubleFormEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
				int seq = PageSize * (CurrentPageIndex - 1);
                while (dataReader.Read())
                {	
					seq++;
                    list.Add(ReaderBind(dataReader, seq));
                }
            }
            return list;
        }
		
		
		/// <summary>
        /// 按条件查询,得到对应的结果列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public override List<tbTroubleFormEntity> GetAllByQuery(string strWhere)
        {
			strWhere = SQLInjectionFilter(strWhere);
            StringBuilder strSql = new StringBuilder();
			strSql.Append("select [ID],[TroubleNo],[ModifyBy],[ServiceID],[TroubleAsset],[TaskSource],[ShortServiceName],[TroubleClassID],[TroubleDescription],[AppendixID],[RequestUserID],[RequestTime],[ExpectTime],[State],[Incidence],[UrgencyDegree],[NextDepartment],[NextPerson],[TransactComments],[Feedback],[CreateDate],[CreateBy],[ModifyDate],[OwnerCompnayID] from tb_TroubleForm ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tbTroubleFormEntity> list = new List<tbTroubleFormEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            { 
				int seq = 0;
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		
		/// <summary>
        /// 按条件查询,得到对应的结果列表
        /// </summary>
        /// <param name="strWhere"></param>
		/// <param name="parameters">sql条件中的参数</param>
        /// <returns></returns>
        public override List<tbTroubleFormEntity> GetAllByQuery(string strWhere, List<IDataParameter> parameters)
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("select [ID],[TroubleNo],[ModifyBy],[ServiceID],[TroubleAsset],[TaskSource],[ShortServiceName],[TroubleClassID],[TroubleDescription],[AppendixID],[RequestUserID],[RequestTime],[ExpectTime],[State],[Incidence],[UrgencyDegree],[NextDepartment],[NextPerson],[TransactComments],[Feedback],[CreateDate],[CreateBy],[ModifyDate],[OwnerCompnayID] from [tb_TroubleForm] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tbTroubleFormEntity> list = new List<tbTroubleFormEntity>();
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            foreach (IDataParameter sp in parameters)
            {
                db.AddInParameter(dbCommand, sp.ParameterName, sp.DbType, sp.Value);
            }

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
				int seq =0 ;
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		

		
		
		/// <summary>
        /// 获取按条件查询以后的结果列表的前指定rowNumber行记录
        /// </summary>
        /// <param name="strWhere">不带where关键字的SQL条件语句</param>
        /// <param name="rowNumber"></param>
        /// <returns></returns>
        public override List<tbTroubleFormEntity> GetAllByQuery(string strWhere, List<IDataParameter> parameters, int rowNumber)
        {

            StringBuilder strSql = new StringBuilder();
			strSql.Append("select top ").Append(rowNumber).Append("  [ID],[TroubleNo],[ModifyBy],[ServiceID],[TroubleAsset],[TaskSource],[ShortServiceName],[TroubleClassID],[TroubleDescription],[AppendixID],[RequestUserID],[RequestTime],[ExpectTime],[State],[Incidence],[UrgencyDegree],[NextDepartment],[NextPerson],[TransactComments],[Feedback],[CreateDate],[CreateBy],[ModifyDate],[OwnerCompnayID] from [tb_TroubleForm] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<tbTroubleFormEntity> list = new List<tbTroubleFormEntity>();
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            foreach (IDataParameter sp in parameters)
            {
                db.AddInParameter(dbCommand, sp.ParameterName, sp.DbType, sp.Value);
            }

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {	
				int seq = 0;
                while (dataReader.Read())
                {
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		/// <summary>
        /// 获取按条件查询以后的结果列表的前指定rowNumber行记录
        /// </summary>
        /// <param name="strWhere">不带where关键字的SQL条件语句: AND AA=@AA</param>
        /// <param name="rowNumber"></param>
        /// <returns></returns>
        public override List<tbTroubleFormEntity> GetAllByQuery(string strWhere, int rowNumber)
        {
		    strWhere = SQLInjectionFilter(strWhere);
            StringBuilder strSql = new StringBuilder();
			
			strSql.Append("select top ").Append(rowNumber).Append("  [ID],[TroubleNo],[ModifyBy],[ServiceID],[TroubleAsset],[TaskSource],[ShortServiceName],[TroubleClassID],[TroubleDescription],[AppendixID],[RequestUserID],[RequestTime],[ExpectTime],[State],[Incidence],[UrgencyDegree],[NextDepartment],[NextPerson],[TransactComments],[Feedback],[CreateDate],[CreateBy],[ModifyDate],[OwnerCompnayID] from [tb_TroubleForm] ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where  " + strWhere);
            }
            List<tbTroubleFormEntity> list = new List<tbTroubleFormEntity>();
            Database db = GetDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
				int seq=0;
                while (dataReader.Read())
                {	
					seq++;
                    list.Add(ReaderBind(dataReader,seq));
                }
            }
            return list;
        }
		
		
		
		
		
		
		
        /// <summary>
        /// 按主键查询对应的实体
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        public override tbTroubleFormEntity GetById(int id)
        {
            StringBuilder strSql = new StringBuilder();
			strSql.Append("select [ID],[TroubleNo],[ModifyBy],[ServiceID],[TroubleAsset],[TaskSource],[ShortServiceName],[TroubleClassID],[TroubleDescription],[AppendixID],[RequestUserID],[RequestTime],[ExpectTime],[State],[Incidence],[UrgencyDegree],[NextDepartment],[NextPerson],[TransactComments],[Feedback],[CreateDate],[CreateBy],[ModifyDate],[OwnerCompnayID] from [tb_TroubleForm]  where ID= @ID ");
				
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, id);
            tbTroubleFormEntity entity = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    entity = ReaderBind(dataReader);
                }
            }
            return entity;

        }
		
		
		 /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override int Save()
        {
			
            if (this.ID ==0)
            {
                this.ID = GetMax("tb_TroubleForm");
            }
            StringBuilder strSql = new StringBuilder();
			strSql.Append("insert into  tb_TroubleForm (");
			strSql.Append("[ID],[TroubleNo],[ModifyBy],[ServiceID],[TroubleAsset],[TaskSource],[ShortServiceName],[TroubleClassID],[TroubleDescription],[AppendixID],[RequestUserID],[RequestTime],[ExpectTime],[State],[Incidence],[UrgencyDegree],[NextDepartment],[NextPerson],[TransactComments],[Feedback],[CreateDate],[CreateBy],[ModifyDate],[OwnerCompnayID] )");
			strSql.Append(" values (");
			strSql.Append("@ID,@TroubleNo,@ModifyBy,@ServiceID,@TroubleAsset,@TaskSource,@ShortServiceName,@TroubleClassID,@TroubleDescription,@AppendixID,@RequestUserID,@RequestTime,@ExpectTime,@State,@Incidence,@UrgencyDegree,@NextDepartment,@NextPerson,@TransactComments,@Feedback,@CreateDate,@CreateBy,@ModifyDate,@OwnerCompnayID)");

            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "ID", DbType.Int32, this.ID);
			db.AddInParameter(dbCommand, "TroubleNo", DbType.String, this.TroubleNo);
			if (this.ModifyBy == null)
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, this.ModifyBy.Value);
			}
			if (this.ServiceID == null)
			{
			db.AddInParameter(dbCommand, "ServiceID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ServiceID", DbType.Int32, this.ServiceID.Value);
			}
			if (this.TroubleAsset == null)
			{
			db.AddInParameter(dbCommand, "TroubleAsset", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TroubleAsset", DbType.Int32, this.TroubleAsset.Value);
			}
			if (this.TaskSource == null)
			{
			db.AddInParameter(dbCommand, "TaskSource", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TaskSource", DbType.Int32, this.TaskSource.Value);
			}
			db.AddInParameter(dbCommand, "ShortServiceName", DbType.String, this.ShortServiceName);
			if (this.TroubleClassID == null)
			{
			db.AddInParameter(dbCommand, "TroubleClassID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TroubleClassID", DbType.Int32, this.TroubleClassID.Value);
			}
			db.AddInParameter(dbCommand, "TroubleDescription", DbType.String, this.TroubleDescription);
			if (this.AppendixID == null)
			{
			db.AddInParameter(dbCommand, "AppendixID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "AppendixID", DbType.Int32, this.AppendixID.Value);
			}
			if (this.RequestUserID == null)
			{
			db.AddInParameter(dbCommand, "RequestUserID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "RequestUserID", DbType.Int32, this.RequestUserID.Value);
			}
			if (this.RequestTime == null)
			{
			db.AddInParameter(dbCommand, "RequestTime", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "RequestTime", DbType.DateTime, this.RequestTime.Value);
			}
			if (this.ExpectTime == null)
			{
			db.AddInParameter(dbCommand, "ExpectTime", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ExpectTime", DbType.DateTime, this.ExpectTime.Value);
			}
			if (this.State == null)
			{
			db.AddInParameter(dbCommand, "State", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "State", DbType.Int32, this.State.Value);
			}
			db.AddInParameter(dbCommand, "Incidence", DbType.String, this.Incidence);
			db.AddInParameter(dbCommand, "UrgencyDegree", DbType.String, this.UrgencyDegree);
			if (this.NextDepartment == null)
			{
			db.AddInParameter(dbCommand, "NextDepartment", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "NextDepartment", DbType.Int32, this.NextDepartment.Value);
			}
			if (this.NextPerson == null)
			{
			db.AddInParameter(dbCommand, "NextPerson", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "NextPerson", DbType.Int32, this.NextPerson.Value);
			}
			db.AddInParameter(dbCommand, "TransactComments", DbType.String, this.TransactComments);
			db.AddInParameter(dbCommand, "Feedback", DbType.String, this.Feedback);
			if (this.CreateDate == null)
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, this.CreateDate.Value);
			}
			if (this.CreateBy == null)
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, this.CreateBy.Value);
			}
			if (this.ModifyDate == null)
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, this.ModifyDate.Value);
			}
			db.AddInParameter(dbCommand, "OwnerCompnayID", DbType.Int32, this.OwnerCompnayID);

			return db.ExecuteNonQuery(dbCommand);
		  
      
        }
		

		
        /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override int Save(tbTroubleFormEntity entity)
        {
			
            if (entity.ID == 0)
            {
                entity.ID = GetMax("tb_TroubleForm");
            }
            StringBuilder strSql = new StringBuilder();
			strSql.Append("insert into  tb_TroubleForm (");
			strSql.Append("[ID],[TroubleNo],[ModifyBy],[ServiceID],[TroubleAsset],[TaskSource],[ShortServiceName],[TroubleClassID],[TroubleDescription],[AppendixID],[RequestUserID],[RequestTime],[ExpectTime],[State],[Incidence],[UrgencyDegree],[NextDepartment],[NextPerson],[TransactComments],[Feedback],[CreateDate],[CreateBy],[ModifyDate],[OwnerCompnayID] )");
			strSql.Append(" values (");
			strSql.Append("@ID,@TroubleNo,@ModifyBy,@ServiceID,@TroubleAsset,@TaskSource,@ShortServiceName,@TroubleClassID,@TroubleDescription,@AppendixID,@RequestUserID,@RequestTime,@ExpectTime,@State,@Incidence,@UrgencyDegree,@NextDepartment,@NextPerson,@TransactComments,@Feedback,@CreateDate,@CreateBy,@ModifyDate,@OwnerCompnayID)");

            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID);
			db.AddInParameter(dbCommand, "TroubleNo", DbType.String, entity.TroubleNo);
			if (entity.ModifyBy == null)
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, entity.ModifyBy.Value);
			}
			if (entity.ServiceID == null)
			{
			db.AddInParameter(dbCommand, "ServiceID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ServiceID", DbType.Int32, entity.ServiceID.Value);
			}
			if (entity.TroubleAsset == null)
			{
			db.AddInParameter(dbCommand, "TroubleAsset", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TroubleAsset", DbType.Int32, entity.TroubleAsset.Value);
			}
			if (entity.TaskSource == null)
			{
			db.AddInParameter(dbCommand, "TaskSource", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TaskSource", DbType.Int32, entity.TaskSource.Value);
			}
			db.AddInParameter(dbCommand, "ShortServiceName", DbType.String, entity.ShortServiceName);
			if (entity.TroubleClassID == null)
			{
			db.AddInParameter(dbCommand, "TroubleClassID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TroubleClassID", DbType.Int32, entity.TroubleClassID.Value);
			}
			db.AddInParameter(dbCommand, "TroubleDescription", DbType.String, entity.TroubleDescription);
			if (entity.AppendixID == null)
			{
			db.AddInParameter(dbCommand, "AppendixID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "AppendixID", DbType.Int32, entity.AppendixID.Value);
			}
			if (entity.RequestUserID == null)
			{
			db.AddInParameter(dbCommand, "RequestUserID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "RequestUserID", DbType.Int32, entity.RequestUserID.Value);
			}
			if (entity.RequestTime == null)
			{
			db.AddInParameter(dbCommand, "RequestTime", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "RequestTime", DbType.DateTime, entity.RequestTime.Value);
			}
			if (entity.ExpectTime == null)
			{
			db.AddInParameter(dbCommand, "ExpectTime", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ExpectTime", DbType.DateTime, entity.ExpectTime.Value);
			}
			if (entity.State == null)
			{
			db.AddInParameter(dbCommand, "State", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "State", DbType.Int32, entity.State.Value);
			}
			db.AddInParameter(dbCommand, "Incidence", DbType.String, entity.Incidence);
			db.AddInParameter(dbCommand, "UrgencyDegree", DbType.String, entity.UrgencyDegree);
			if (entity.NextDepartment == null)
			{
			db.AddInParameter(dbCommand, "NextDepartment", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "NextDepartment", DbType.Int32, entity.NextDepartment.Value);
			}
			if (entity.NextPerson == null)
			{
			db.AddInParameter(dbCommand, "NextPerson", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "NextPerson", DbType.Int32, entity.NextPerson.Value);
			}
			db.AddInParameter(dbCommand, "TransactComments", DbType.String, entity.TransactComments);
			db.AddInParameter(dbCommand, "Feedback", DbType.String, entity.Feedback);
			if (entity.CreateDate == null)
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, entity.CreateDate.Value);
			}
			if (entity.CreateBy == null)
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, entity.CreateBy.Value);
			}
			if (entity.ModifyDate == null)
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, entity.ModifyDate.Value);
			}
			db.AddInParameter(dbCommand, "OwnerCompnayID", DbType.Int32, entity.OwnerCompnayID);

			return db.ExecuteNonQuery(dbCommand);
		  
      
        }
		
		
        /// <summary>
        /// 保存或者更新(如果传入的实体主键为空则保存,否则做更新操作)
        /// </summary>
        /// <param name="entity">传入的实体</param>
        /// <returns>影响的行数</returns>
        public override int SaveOrUpdate(tbTroubleFormEntity entity)
        {
			
            if (entity.ID  == 0)
            {
                if (Save(entity)>0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                return Update(entity);
            }
        }
		
		/// <summary>
        /// 保存或者更新(如果传入的实体主键为空则保存,否则做更新操作)
        /// </summary>
        /// <param name="entity">传入的实体</param>
        /// <returns>影响的行数</returns>
        public override int SaveOrUpdate()
        {
		
            if (this.ID  == 0)
            {
                if (Save()>0)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                return Update();
            }
        }
		
		/// <summary>
        /// 是否存在对应主键ID的记录
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public override bool IsExist(int ID)
        {
            Database db = GetDatabase();
            StringBuilder strSql = new StringBuilder();
            			 strSql.Append("select count(1) from tb_TroubleForm where ID=@ID ");

            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, ID);//这里为ID是因为原有代码把主键都变成了ID.
            int cmdresult;
            object obj = db.ExecuteScalar(dbCommand);
            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
		
		
		/// <summary>
        /// 删除对应的实体
        /// </summary>
        /// <param name="entity"></param>
        public override int Delete(tbTroubleFormEntity entity)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete tb_TroubleForm ");
            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID );
            return db.ExecuteNonQuery(dbCommand);
        }
		
		/// <summary>
        /// 删除主键ID对应的记录
        /// </summary>
        /// <param name="id"></param>
        public override int Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete tb_TroubleForm ");
            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ID", DbType.Int32, id);
            return db.ExecuteNonQuery(dbCommand);
        }
		
		
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public override int Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update tb_TroubleForm set ");
			strSql.Append("[ID]=@ID,[TroubleNo]=@TroubleNo,[ModifyBy]=@ModifyBy,[ServiceID]=@ServiceID,[TroubleAsset]=@TroubleAsset,[TaskSource]=@TaskSource,[ShortServiceName]=@ShortServiceName,[TroubleClassID]=@TroubleClassID,[TroubleDescription]=@TroubleDescription,[AppendixID]=@AppendixID,[RequestUserID]=@RequestUserID,[RequestTime]=@RequestTime,[ExpectTime]=@ExpectTime,[State]=@State,[Incidence]=@Incidence,[UrgencyDegree]=@UrgencyDegree,[NextDepartment]=@NextDepartment,[NextPerson]=@NextPerson,[TransactComments]=@TransactComments,[Feedback]=@Feedback,[CreateDate]=@CreateDate,[CreateBy]=@CreateBy,[ModifyDate]=@ModifyDate,[OwnerCompnayID]=@OwnerCompnayID ");

            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
			DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "ID", DbType.Int32, this.ID );
			db.AddInParameter(dbCommand, "TroubleNo", DbType.String, this.TroubleNo);
			if (this.ModifyBy == null)
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, this.ModifyBy.Value);
			}
			if (this.ServiceID == null)
			{
			db.AddInParameter(dbCommand, "ServiceID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ServiceID", DbType.Int32, this.ServiceID.Value);
			}
			if (this.TroubleAsset == null)
			{
			db.AddInParameter(dbCommand, "TroubleAsset", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TroubleAsset", DbType.Int32, this.TroubleAsset.Value);
			}
			if (this.TaskSource == null)
			{
			db.AddInParameter(dbCommand, "TaskSource", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TaskSource", DbType.Int32, this.TaskSource.Value);
			}
			db.AddInParameter(dbCommand, "ShortServiceName", DbType.String, this.ShortServiceName);
			if (this.TroubleClassID == null)
			{
			db.AddInParameter(dbCommand, "TroubleClassID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TroubleClassID", DbType.Int32, this.TroubleClassID.Value);
			}
			db.AddInParameter(dbCommand, "TroubleDescription", DbType.String, this.TroubleDescription);
			if (this.AppendixID == null)
			{
			db.AddInParameter(dbCommand, "AppendixID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "AppendixID", DbType.Int32, this.AppendixID.Value);
			}
			if (this.RequestUserID == null)
			{
			db.AddInParameter(dbCommand, "RequestUserID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "RequestUserID", DbType.Int32, this.RequestUserID.Value);
			}
			if (this.RequestTime == null)
			{
			db.AddInParameter(dbCommand, "RequestTime", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "RequestTime", DbType.DateTime, this.RequestTime.Value);
			}
			if (this.ExpectTime == null)
			{
			db.AddInParameter(dbCommand, "ExpectTime", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ExpectTime", DbType.DateTime, this.ExpectTime.Value);
			}
			if (this.State == null)
			{
			db.AddInParameter(dbCommand, "State", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "State", DbType.Int32, this.State.Value);
			}
			db.AddInParameter(dbCommand, "Incidence", DbType.String, this.Incidence);
			db.AddInParameter(dbCommand, "UrgencyDegree", DbType.String, this.UrgencyDegree);
			if (this.NextDepartment == null)
			{
			db.AddInParameter(dbCommand, "NextDepartment", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "NextDepartment", DbType.Int32, this.NextDepartment.Value);
			}
			if (this.NextPerson == null)
			{
			db.AddInParameter(dbCommand, "NextPerson", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "NextPerson", DbType.Int32, this.NextPerson.Value);
			}
			db.AddInParameter(dbCommand, "TransactComments", DbType.String, this.TransactComments);
			db.AddInParameter(dbCommand, "Feedback", DbType.String, this.Feedback);
			if (this.CreateDate == null)
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, this.CreateDate.Value);
			}
			if (this.CreateBy == null)
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, this.CreateBy.Value);
			}
			if (this.ModifyDate == null)
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, this.ModifyDate.Value);
			}
			db.AddInParameter(dbCommand, "OwnerCompnayID", DbType.Int32, this.OwnerCompnayID);

			
			return	db.ExecuteNonQuery(dbCommand);

		}
		



		
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public override int Update(tbTroubleFormEntity entity)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update tb_TroubleForm set ");
			strSql.Append("[ID]=@ID,[TroubleNo]=@TroubleNo,[ModifyBy]=@ModifyBy,[ServiceID]=@ServiceID,[TroubleAsset]=@TroubleAsset,[TaskSource]=@TaskSource,[ShortServiceName]=@ShortServiceName,[TroubleClassID]=@TroubleClassID,[TroubleDescription]=@TroubleDescription,[AppendixID]=@AppendixID,[RequestUserID]=@RequestUserID,[RequestTime]=@RequestTime,[ExpectTime]=@ExpectTime,[State]=@State,[Incidence]=@Incidence,[UrgencyDegree]=@UrgencyDegree,[NextDepartment]=@NextDepartment,[NextPerson]=@NextPerson,[TransactComments]=@TransactComments,[Feedback]=@Feedback,[CreateDate]=@CreateDate,[CreateBy]=@CreateBy,[ModifyDate]=@ModifyDate,[OwnerCompnayID]=@OwnerCompnayID ");

            strSql.Append(" where ID=@ID ");
            Database db = GetDatabase();
			DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "ID", DbType.Int32, entity.ID );
			db.AddInParameter(dbCommand, "TroubleNo", DbType.String, entity.TroubleNo);
			if (entity.ModifyBy == null)
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyBy", DbType.Int32, entity.ModifyBy.Value);
			}
			if (entity.ServiceID == null)
			{
			db.AddInParameter(dbCommand, "ServiceID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ServiceID", DbType.Int32, entity.ServiceID.Value);
			}
			if (entity.TroubleAsset == null)
			{
			db.AddInParameter(dbCommand, "TroubleAsset", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TroubleAsset", DbType.Int32, entity.TroubleAsset.Value);
			}
			if (entity.TaskSource == null)
			{
			db.AddInParameter(dbCommand, "TaskSource", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TaskSource", DbType.Int32, entity.TaskSource.Value);
			}
			db.AddInParameter(dbCommand, "ShortServiceName", DbType.String, entity.ShortServiceName);
			if (entity.TroubleClassID == null)
			{
			db.AddInParameter(dbCommand, "TroubleClassID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "TroubleClassID", DbType.Int32, entity.TroubleClassID.Value);
			}
			db.AddInParameter(dbCommand, "TroubleDescription", DbType.String, entity.TroubleDescription);
			if (entity.AppendixID == null)
			{
			db.AddInParameter(dbCommand, "AppendixID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "AppendixID", DbType.Int32, entity.AppendixID.Value);
			}
			if (entity.RequestUserID == null)
			{
			db.AddInParameter(dbCommand, "RequestUserID", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "RequestUserID", DbType.Int32, entity.RequestUserID.Value);
			}
			if (entity.RequestTime == null)
			{
			db.AddInParameter(dbCommand, "RequestTime", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "RequestTime", DbType.DateTime, entity.RequestTime.Value);
			}
			if (entity.ExpectTime == null)
			{
			db.AddInParameter(dbCommand, "ExpectTime", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ExpectTime", DbType.DateTime, entity.ExpectTime.Value);
			}
			if (entity.State == null)
			{
			db.AddInParameter(dbCommand, "State", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "State", DbType.Int32, entity.State.Value);
			}
			db.AddInParameter(dbCommand, "Incidence", DbType.String, entity.Incidence);
			db.AddInParameter(dbCommand, "UrgencyDegree", DbType.String, entity.UrgencyDegree);
			if (entity.NextDepartment == null)
			{
			db.AddInParameter(dbCommand, "NextDepartment", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "NextDepartment", DbType.Int32, entity.NextDepartment.Value);
			}
			if (entity.NextPerson == null)
			{
			db.AddInParameter(dbCommand, "NextPerson", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "NextPerson", DbType.Int32, entity.NextPerson.Value);
			}
			db.AddInParameter(dbCommand, "TransactComments", DbType.String, entity.TransactComments);
			db.AddInParameter(dbCommand, "Feedback", DbType.String, entity.Feedback);
			if (entity.CreateDate == null)
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, entity.CreateDate.Value);
			}
			if (entity.CreateBy == null)
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "CreateBy", DbType.Int32, entity.CreateBy.Value);
			}
			if (entity.ModifyDate == null)
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, System.DBNull.Value);
			}
			else
			{
			db.AddInParameter(dbCommand, "ModifyDate", DbType.DateTime, entity.ModifyDate.Value);
			}
			db.AddInParameter(dbCommand, "OwnerCompnayID", DbType.Int32, entity.OwnerCompnayID);

			
			return	db.ExecuteNonQuery(dbCommand);

		}
		


		
		
		
		
		/// <summary>
        /// 对象实体绑定数据
		///生成构造为list的构造器
        /// </summary>
        private tbTroubleFormEntity ReaderBind(IDataReader dataReader,int seq)
        {
            ITOMMS.Entity.tbTroubleFormEntity entity = new ITOMMS.Entity.tbTroubleFormEntity();
			entity.SEQNO = seq;
            object obj;
			obj = dataReader["ID"];
			 if (obj != null && obj != DBNull.Value)
			 {
			 entity.ID = (int)obj;
			 }
			 entity.TroubleNo= dataReader["TroubleNo"].ToString();
			 obj=dataReader["ModifyBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyBy= (int)obj;
			}
			 obj=dataReader["ServiceID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ServiceID= (int)obj;
			}
			 obj=dataReader["TroubleAsset"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.TroubleAsset= (int)obj;
			}
			 obj=dataReader["TaskSource"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.TaskSource= (int)obj;
			}
			 entity.ShortServiceName= dataReader["ShortServiceName"].ToString();
			 obj=dataReader["TroubleClassID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.TroubleClassID= (int)obj;
			}
			 entity.TroubleDescription= dataReader["TroubleDescription"].ToString();
			 obj=dataReader["AppendixID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.AppendixID= (int)obj;
			}
			 obj=dataReader["RequestUserID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.RequestUserID= (int)obj;
			}
			 obj=dataReader["RequestTime"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.RequestTime= (DateTime)obj;
			}
			 obj=dataReader["ExpectTime"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ExpectTime= (DateTime)obj;
			}
			 obj=dataReader["State"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.State= (int)obj;
			}
			 entity.Incidence= dataReader["Incidence"].ToString();
			 entity.UrgencyDegree= dataReader["UrgencyDegree"].ToString();
			 obj=dataReader["NextDepartment"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.NextDepartment= (int)obj;
			}
			 obj=dataReader["NextPerson"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.NextPerson= (int)obj;
			}
			 entity.TransactComments= dataReader["TransactComments"].ToString();
			 entity.Feedback= dataReader["Feedback"].ToString();
			 obj=dataReader["CreateDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateDate= (DateTime)obj;
			}
			 obj=dataReader["CreateBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateBy= (int)obj;
			}
			 obj=dataReader["ModifyDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyDate= (DateTime)obj;
			}
			 obj=dataReader["OwnerCompnayID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.OwnerCompnayID= (int)obj;
			}

            return entity;
        }
		
		
				/// <summary>
        /// 对象实体绑定数据
		///生成构造为list的构造器
        /// </summary>
        private tbTroubleFormEntity ReaderBind(IDataReader dataReader)
        {
            ITOMMS.Entity.tbTroubleFormEntity entity = new ITOMMS.Entity.tbTroubleFormEntity();
			object obj;
			obj = dataReader["ID"];
			 if (obj != null && obj != DBNull.Value)
			 {
			 entity.ID = (int)obj;
			 }
			 entity.TroubleNo= dataReader["TroubleNo"].ToString();
			 obj=dataReader["ModifyBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyBy= (int)obj;
			}
			 obj=dataReader["ServiceID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ServiceID= (int)obj;
			}
			 obj=dataReader["TroubleAsset"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.TroubleAsset= (int)obj;
			}
			 obj=dataReader["TaskSource"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.TaskSource= (int)obj;
			}
			 entity.ShortServiceName= dataReader["ShortServiceName"].ToString();
			 obj=dataReader["TroubleClassID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.TroubleClassID= (int)obj;
			}
			 entity.TroubleDescription= dataReader["TroubleDescription"].ToString();
			 obj=dataReader["AppendixID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.AppendixID= (int)obj;
			}
			 obj=dataReader["RequestUserID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.RequestUserID= (int)obj;
			}
			 obj=dataReader["RequestTime"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.RequestTime= (DateTime)obj;
			}
			 obj=dataReader["ExpectTime"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ExpectTime= (DateTime)obj;
			}
			 obj=dataReader["State"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.State= (int)obj;
			}
			 entity.Incidence= dataReader["Incidence"].ToString();
			 entity.UrgencyDegree= dataReader["UrgencyDegree"].ToString();
			 obj=dataReader["NextDepartment"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.NextDepartment= (int)obj;
			}
			 obj=dataReader["NextPerson"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.NextPerson= (int)obj;
			}
			 entity.TransactComments= dataReader["TransactComments"].ToString();
			 entity.Feedback= dataReader["Feedback"].ToString();
			 obj=dataReader["CreateDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateDate= (DateTime)obj;
			}
			 obj=dataReader["CreateBy"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.CreateBy= (int)obj;
			}
			 obj=dataReader["ModifyDate"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.ModifyDate= (DateTime)obj;
			}
			 obj=dataReader["OwnerCompnayID"];
			if(obj != null && obj != DBNull.Value)
			{
			 entity.OwnerCompnayID= (int)obj;
			}

            return entity;
        }
		
		
		
		 #endregion
		
	}
}
